<?php

namespace admin\controllers;

use app\models\Admin;
use admin\components\BaseAuthController;

class UserController extends BaseAuthController {

    public $name = '账号管理';

    public function actionIndex() {
        $model = new Admin();
        $model->with = ['group'];
        $dataProvider = $model->search();
        return $this->render(compact('dataProvider'));
    }

    public function actionSave($id = FALSE) {
        /* @var $model Admin */
        $model = $this->findModel($id, Admin::className());
        $model->setScenario($model->isNewRecord ? 'new' : 'save');

        $checkAccess = $this->checkAccessByGroup(FALSE);
        if (!$model->load($this->post())) {
            return $this->render(compact('model', 'checkAccess'));
        }

        return $model->saveAdmin();
    }

}
